package com.qiangqiang.task.server.mapper.provider;

import com.qiangqiang.task.server.entity.Follow;
import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

/**
 * @program: task
 * @description:
 * @author: Sky.lin
 * @create: 2018-12-31 14:21
 **/
public class FollowProvider extends BaseProvider {

    public String insertFollow(final Map<String, Object> map) {
        Follow follow = (Follow) map.get("follow");
        return generateInsertSQL(Follow.class);
    }

    public String queryFollowsOrFans(final Map<String,Object> map){
        long userId= (long) map.get("userId");
        boolean isFindFans= (boolean) map.get("isFindFans");


        SQL sql = new SQL() {
            {
                SELECT("*");
                FROM("follow ");
                if (isFindFans){
                    WHERE("followed_user_id="+userId);
                }else {
                    WHERE("user_id="+userId);
                }
                ORDER_BY("update_time desc ");
            }
        };
        StringBuffer sb = new StringBuffer(sql.toString());
        return sb.toString();
    }
}
